package server.controller.storeController;

import server.entity.Store;
import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.InfoUtils.InfoEnum;
import server.util.InfoUtils.InfoUtil;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/setStoreInfo")
public class SetStoreInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1325034082138032176L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Info info = null;
        Store store = MyUtils.convertRequest2Bean(req, Store.class);
        System.out.println(store);

        //获取storeId
        Integer storeId = ModelFactory.getStoreModel().getStoreId(req);
        if (MyUtils.NOTNULL(storeId.toString())) {
            store.setStoreId(storeId);
            info = ModelFactory.getStoreInfoModel().setStoreInfo(store);
        } else {
            info = InfoUtil.getInfo(InfoEnum.FAIL);
        }
        ResponseUtil.responseMessage(resp, info);
    }
}


